﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Recharge.aspx.cs" Inherits="WISD.CarFriend.Web.Admin.OA.RechargeManage.Recharge" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>会员卡充值管理</title>
    <link href="../../Content/CSS/ClientCSS/qlsale.css" rel="stylesheet" type="text/css" />
    <link href="../../Content/CSS/ClientCSS/Table.css" rel="stylesheet" type="text/css" />
    <link href="../../Content/CSS/ClientCSS/blue.css" rel="stylesheet" type="text/css" />
    <script src="/Admin/Scripts/ClientScripts/Page.js" type="text/javascript"></script>
    <script src="/Admin/Scripts/ClientScripts/CodyyForm.js" type="text/javascript"></script>
    <script src="/Admin/Scripts/ClientScripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script src="/Admin/Scripts/DatePicker/WdatePicker.js" type="text/javascript"></script>
    <script src="/Admin/Scripts/ClientScripts/SplitPage.js" type="text/javascript"></script>
    <script src="/Admin/Scripts/ClientScripts/jquery.artDialog.min.js" type="text/javascript"></script>
    <script src="/Admin/Scripts/WisdScript/Common.js" type="text/javascript"></script>
</head>
<body>
    <div style="height: auto;">
        <table class="adduser" align="center" border="0" cellpadding="0" cellspacing="0"
            width="100%" bgcolor="#F2F7F5">
            <tbody>
                <tr>
                    <td colspan="5" class="bigTitle" height="40">
                        <strong>会员卡充值管理</strong>
                    </td>
                </tr>
                <tr>
                    <td class="sctitle" style="width: 81px;">
                        会员卡号：
                    </td>
                    <td style="width: 162px;">
                        <input id="txtMemberCardID1" class="xstxt" type="text" />
                    </td>
                    <td class="sctitle" style="width: 50px;"></td>
                    <td class="sctitle" style="width: 81px;">
                        经办人：
                    </td>
                    <td>
                        <input id="txtReviser1" class="xstxt" type="text" />
                    </td>
                </tr>
                <tr>
                    <td colspan="5" class="fenline">
                        &nbsp;
                        <input value="搜索" class="twobtn" type="button" id="btnSearch" />&nbsp;&nbsp;
                        <input class="twobtn" value="新增" type="button" id="btnAdd" />&nbsp;
                    </td>
                </tr>
                <tr>
                    <td colspan="5">
                        <table rules="all" class="tableStyle">
                            <thead>
                                <tr>
                                    <th scope="col" style="display: none;">
                                        序号
                                    </th>
                                    <th scope="col">
                                        会员卡号
                                    </th>
                                    <th scope="col">
                                        充值金额
                                    </th>
                                    <th scope="col">
                                        实收金额
                                    </th>
                                    <th scope="col">
                                        经办人
                                    </th>
                                    <th scope="col">
                                        充值时间
                                    </th>
                                </tr>
                            </thead>
                            <tbody id="databody">
                            </tbody>
                            <tfoot id="footer" class="div_footer">
                            </tfoot>
                        </table>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
    <div id="registerdiv" class="registerdiv" style="width: 500px;">
        <table class="addTable" align="center" border="0" cellpadding="0" cellspacing="0"
            width="500">
            <tbody>
                <tr class="topTitle">
                    <td colspan="4" style="margin-top: -3px;">
                        <ul>
                            <li class="leftli">会员卡充值</li>
                            <li class="rightli" onclick="$('#registerdiv').hide();">
                                <img alt="关闭" title="关闭" id="close" src="/Admin/Content/Images/tdClose_Hover.png" /></li>
                        </ul>
                    </td>
                </tr>
                <tr>
                    <td class="sctitle_four">
                        会员卡号：
                    </td>
                    <td colspan="3"'>
                        <input id="txtMemberCardID" name="MemberCardID" class="stxt" type="text" reg="\S" needcheck="yes"
                            tip="['会员卡号不能为空','只能为中英文','长度在1-50之间']" scope="1,50" clear="yes" />
                        <span></span>
                    </td>
                </tr>
                <tr>
                    <td class="sctitle_four">
                        充值金额：
                    </td>
                    <td>
                        <input id="txtRechargeAmount" name="RechargeAmount" class="stxt" type="text" reg="^[1-9]\d*$"
                            needcheck="yes" tip="['充值金额不能为空','只能正整数','长度在1-50之间']" scope="1,50" clear="yes" />
                        <span></span>
                    </td>
                    <td class="sctitle_four">
                        实收金额:
                    </td>
                    <td>
                        <input id="txtPaidAmount" name="PaidAmount" class="stxt" type="text" reg="^[1-9]\d*$"
                            needcheck="yes" tip="['实收金额不能为空','只能正整数','长度在1-50之间']" scope="1,50" clear="yes" />
                        <span></span>
                    </td>
                </tr>
                <tr>
                    <td class="sctitle_four">
                        经办人：
                    </td>
                    <td>
                        <input id="txtReviser" name="Reviser" class="stxt" type="text"  readonly="readonly" />
                    </td>
                    <td class="sctitle_four">
                        充值时间：
                    </td>
                    <td>
                        <input id="txtReviseDate" name="ReviseDate" class="stxt" type="text" readonly="readonly" />
                        <span></span>
                    </td>
                </tr>
                <tr>
                    <td class="sctitle_four">
                        备注：
                    </td>
                    <td colspan="3">
                        <textarea id="txtMemo" cols="30" rows="5" style="overflow: hidden; display: block; resize: none;" clear="yes"></textarea>
                    </td>
                </tr>
                <tr>
                    <td colspan="4" style="height: 15px;">
                    </td>
                </tr>
                <tr>
                    <td id="btnGroup" colspan="4" align="center" style="text-align: center;">
                        <input value="修改" id="btnEdit" class="twobtn" type="button" />&nbsp;&nbsp;
                        <input value="保存" id="btnSave" class="twobtn" type="button" />&nbsp;&nbsp;
                        <input id="btnRest" class="twobtn" value="重置" type="button" />
                    </td>
                </tr>
                <tr>
                    <td colspan="4" style="height: 15px;">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
    
</body>
</html>
<script type="text/javascript">
    var rs = {};
    var MainPK = "";
    var Condition = "";
    var CurrentPage = 1;
    var artDialog;

    //赋值操作
    function EditEntity() {
        var rs = Page.Static.Rs[0];
        $("#txtMemberCardID").val(rs["MemberCardID"]);
        $("#txtRechargeAmount").val(rs["RechargeAmount"]);
        $("#txtPaidAmount").val(rs["PaidAmount"]);
        $("#txtReviser").val(rs["Reviser"]);
        $("#txtReviseDate").val(rs["ReviseDate"].split(" ")[0]);
        $("#txtMemo").val(rs["Memo"]);
    };

    //添加修改记录
    var setEntity = function (obj) {
        var Result = Form.Validator({ id: "registerdiv" });
        if (Result) {
            var _$ = function (id) { return document.getElementById(id); };
            var data = {
                Action: obj.Action
                    , MemberCardID: $.trim($("#txtMemberCardID").val())
                    , RechargeAmount: $.trim($("#txtRechargeAmount").val())
                    , PaidAmount: $.trim($("#txtPaidAmount").val())
                    , Reviser: $.trim($("#txtReviser").val())
                    , ReviseDate: $.trim($("#txtReviseDate").val())
                    , Memo: $.trim($("#txtMemo").val())
            };
            if (obj.Action == "EditEntity") { data["Main"] = obj.Main; }
            $.post("/Admin/Control/Recharge.ashx", data, function (data) {
                if (data.split(",")[0] === "Success") {
                    if (obj.Action == "AddEntity") {
                        alert("添加成功!");
                        Condition = GetCondition();
                        CurrentPage = Page.Static.CurrentPage;
                        InitPage();
                    }
                    else {
                        alert("修改成功!");
                        Condition = GetCondition();
                        CurrentPage = Page.Static.CurrentPage;
                        InitPage();
                    }
                }
                else {
                    obj.Action == "AddEntity" ? alert("添加失败！") : alert("修改失败！"); ;
                }
            });
        }
    };

    //获取查询条件
    var GetCondition = function () {
        var MemberCardID = $("#txtMemberCardID1").val() || "null"; //会员卡号
        var Reviser = $("#txtReviser1").val() || "null"; //经办人
        return MemberCardID + "@" + Reviser;
    };

    //加载数据
    var InitPage = function () {
        Page.GetData({ "Control": "/Admin/Control/Recharge.ashx", "Action": "Init", "first": true, "colspan": 50, "Condition": Condition, "CurrentPage": CurrentPage, "databody": "databody", "footer": "footer", "ActionBtn": "" });
    };

    //显示经办人
    var GetReviser = function () {
        $.post("/Admin/Control/Recharge.ashx", { "Action": "GetReviser" }, function (data) {
            var jsonArr = eval("(" + data + ")");
            var reviser = jsonArr[0]["reviser"];
            $("#txtReviser").val(reviser);
        });
    };

    //重置表单
    var ResetForm = function () {
        $(".addTable").find("input,textarea,select").attr("disabled", false);
        $(".addTable").find("input[type='text'][clear='yes'],input[type='password'][clear='yes'],textarea[clear='yes']").val("");
    };

    $(function () {
        //失去焦点验证
        Form.Blur({ id: "registerdiv" });

        //第一次加载数据
        Condition = GetCondition();
        InitPage();

        //点击搜索按钮
        $("#btnSearch").click(function () {
            Condition = GetCondition();
            CurrentPage = 1;
            InitPage();
        });

        //点击新增按钮
        $("#btnAdd").click(function () {
            ResetForm();
            GetReviser();
            $("#txtReviseDate").val(getNowFormatDate()).addClass("txtgray");
            $("#btnSave,#btnRest").show();
            $("#btnEdit").hide();
            $(".leftli").html("添加会员卡");
            Page.divCenter($("#registerdiv")[0]);
        });

        //点击保存按钮
        $("#btnSave").click(function () {
            var Result = Form.Validator({ id: "registerdiv" });
            if (Result) {
                $.post("/Admin/Control/Recharge.ashx", { "Action": "CheckMemberState", "MemberCardID": $.trim($("#txtMemberCardID").val()) }, function (data) {
                    if (data.split(",")[0] === "Success") {
                        setEntity({ "Action": "AddEntity" });
                    }
                    else {
                        alert("会员卡状态处于非正常状态，不可充值！请先修改会员卡状态！");
                    }
                });
            }
        });

        //点击重置按钮
        $("#btnRest").click(function () {
            ResetForm();
        });

        //点击修改按钮
        $("#btnEdit").click(function () {
            setEntity({ "Action": "EditEntity", "Main": MainPK });
        });

        //在Table中点击修改、删除 
        $("#databody").click(function (e) {
            var that = this;
            var e = e || window.event;
            var target = e.srcElement || e.target;
            if ($(target).is("a")) {
                var action = $(target).attr("action");
                var main = $(target).parent().parent().attr("main");
                MainPK = main;
                if (!action.localeCompare("edit")) {    //编辑
                    ResetForm();
                    $("#btnSave,#btnRest").hide();
                    $("#btnEdit").show();
                    $(".leftli").html("修改会员卡充值记录");
                    var divobj = $("#registerdiv");
                    Page.divCenter(divobj[0]).GetOne({ "Main": main });
                }
                if (!action.localeCompare("delete")) {    //删除
                    if (confirm("是否确定删除该记录?")) {
                        Page.DeleteEntity({ "Main": main });
                    }
                }
                (! -[1, ]) ? e.cancelBubble = true : e.stopPropagation();
            }
        }).dblclick(function (e) {    //双击查看详细信息
            var that = this;
            var e = e || window.event;
            var target = e.srcElement || e.target;
            if ($(target.parentNode).is("tr")) {
                var main = $(target.parentNode).attr("main");
                ResetForm();
                $("#btnEdit,#btnSave,#btnRest").hide();
                $(".addTable").find("input,textarea,select").attr("disabled", true);
                $(".leftli").html("会员卡充值信息");
                var divobj = $("#registerdiv");
                Page.divCenter(divobj[0]).GetOne({ "Main": main });
                (! -[1, ]) ? e.cancelBubble = true : e.stopPropagation();
            }
        });

    });
</script>
